package ch.christianschweizer.epk.common.framework;

import oracle.jbo.AttributeDef;
import oracle.jbo.AttributeList;
import oracle.jbo.server.SequenceImpl;

public class EntityImpl extends oracle.jbo.server.EntityImpl {

    private static final String PROPERTY_SEQUENCE_NAME = "SEQUENCE_NAME";

    protected void create(AttributeList attributeList) {
        super.create(attributeList);
        for (AttributeDef def : getEntityDef().getAttributeDefs()) {
            String sequenceName = (String)def.getProperty(PROPERTY_SEQUENCE_NAME);
            if (sequenceName != null) {
                SequenceImpl s = new SequenceImpl(sequenceName, getDBTransaction());
                setAttribute(def.getIndex(), s.getSequenceNumber().bigDecimalValue());
            }
        }
    }

}
